<script lang="ts" setup name="Toolbar">
import useSettingsStore from '@g/store/modules/settings'
import useMenuStore from '@g/store/modules/menu'
import Tools from '../../Tools/index.vue'
import SidebarItem from '../../SidebarItem/main.vue'
import ToolbarSlogan from './ToolbarSlogan.vue'
// import { InjectionI18nTitle } from '@/global/utils/injection-keys'
import { systemConfig } from '@/system.config'

const navBg = `url(/system-config/${systemConfig.navBg})`
const navBgDark = `url(/system-config/${systemConfig.navBgDark})`

const settingsStore = useSettingsStore()
const menuStore = useMenuStore()

// const generateI18nTitle = inject(InjectionI18nTitle) as Function

const { switchTo } = useMenu()

// const navRef = ref()
// 顶部模式鼠标滚动
// function handlerMouserScroll(event: WheelEvent) {
//   navRef.value.scrollBy({
//     left: (event.deltaY || event.detail) > 0 ? 50 : -50
//   })
// }

const route = useRoute()

const isHead = computed(() => settingsStore.settings.menu.menuMode === EMenuModel.HEAD)
const isSingle = computed(() => [EMenuModel.SIDE, EMenuModel.SINGLE, EMenuModel.ONLY_SIDE].includes(settingsStore.settings.menu.menuMode))
</script>

<template>
  <div class="toolbar-container">
    <div v-if="!isHead" class="left-box" :class="{ 'is-single': isSingle }">
      <!-- <Breadcrumb /> -->
      <ToolbarSlogan v-if="isSingle" />
    </div>
    <template v-else>
      <!-- <div
        v-if="isHead"
        ref="navRef"
        class="nav"
        :class="{
          [`nav-fill-${settingsStore.settings.menu.menuFillStyle}`]:
            settingsStore.settings.menu.menuFillStyle !== '',
          [`nav-active-${settingsStore.settings.menu.menuActiveStyle}`]:
            settingsStore.settings.menu.menuActiveStyle !== '',
        }"
        @wheel.prevent="handlerMouserScroll"
      > -->
      <!-- <template v-for="(item, index) in menuStore.allMenus" :key="index"> -->
      <!-- <div
            v-if="item.children && item.children.length !== 0"
            class="item-container"
            :class="{ active: index === menuStore.actived }"
          >
            <div class="item" @click="switchTo(index)">
              <span>{{ generateI18nTitle(item.meta?.i18n, item.meta?.title) }} ----</span>
            </div>
          </div> -->
      <!-- <SidebarItem :item="item" /> -->
      <!-- </template> -->
      <el-menu
        v-if="isHead"
        collapse
        mode="horizontal"
        :default-active="route.meta.activeMenu || route.path"
        class="flex-1 fa-menu"
      >
        <SidebarItem
          v-for="(itemRoute, index) in menuStore.fatherMenus"
          :key="index"
          :class="{ active: index === menuStore.actived }"
          :item="itemRoute"
          @hand-link="switchTo(index, itemRoute)"
        />
      </el-menu>
      <!-- </div> -->
    </template>

    <Tools />
  </div>
</template>

<style lang="scss" scoped>
:root.dark {
  .toolbar-container {
    background-image: v-bind(navBgDark);
  }
}

.toolbar-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--ik-toolbar-height);
  background-color: var(--ik-toolbar-bg);
  box-shadow: 0 0 1px 0 var(--el-border-color);
  transition: background-color 0.3s, var(--el-transition-box-shadow);
  border-bottom: 1px solid var(--el-border-color);
  background-size: 100% 100%;
  background-image: v-bind(navBg);
  padding-left: 20px;

  .el-menu {
    background-color: transparent;
    border: none;

    :deep(.sidebar-item) {
      .el-menu-item {
        height: 36px;
        border-radius: 5px;
        margin: 4px 0;
        padding: 0 16px;

        &:not(.is-disabled):hover{
          background-color: transparent !important;
        }
      }

      &.active .el-menu-item {
        color: var(--ik-header-menu-active-color) !important;
        background-color: var(--ik-header-menu-active-bg) !important;
        --ik-main-icon-deep-color: var(--el-color-primary);
        --ik-main-icon-color: var(--ik-theme-color-re);

        &:hover{
          background-color: var(--ik-header-menu-active-bg) !important;
        }
      }
    }
  }

  .left-box {
    display: flex;
    align-items: center;
    padding-right: 50px;
    overflow: hidden;
    height: 100%;

    // mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 50px), transparent);
    &.is-single {
      flex: 1;
      justify-content: center;
      padding-right: 0;
    }

    .sidebar-collapse {
      display: flex;
      align-items: center;
      padding: 0 20px;
      height: 50px;
      cursor: pointer;

      .el-icon {
        color: var(--ik-main-icon-deep-color);
        transition: var(--el-transition-color), var(--el-transition-md-fade);
      }

      &:hover .el-icon {
        color: var(--el-color-primary);
      }

      &.is-collapse .el-icon {
        transform: rotateZ(-180deg);
      }

      &+.el-breadcrumb {
        margin-left: 0;
      }
    }

    .breadcrumb {
      margin-left: 20px;
      white-space: nowrap;

      :deep(.el-breadcrumb__item) {
        display: inline-block;
        float: none;

        span {
          font-weight: normal;
        }

        &:last-child .el-breadcrumb__inner {
          color: var(--el-text-color-secondary);
          transition: var(--el-transition-color);
        }
      }

      &.breadcrumb-modern {
        :deep(.el-breadcrumb__item) {
          .el-breadcrumb__inner {
            display: inline-block;
            background-color: var(--el-fill-color);
            transition: background-color 0.3s, var(--el-transition-color);
            padding: 8px 16px;
            clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%);

            &.is-link:hover {
              background-color: var(--el-fill-color-darker);
            }
          }

          &:first-child:not(:last-child) .el-breadcrumb__inner {
            padding-left: 12px;
            border-radius: 6px 0 0 6px;
            clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%);
          }

          &:last-child:not(:first-child) .el-breadcrumb__inner {
            background-color: var(--el-fill-color-darker);
            padding-right: 12px;
            border-radius: 0 6px 6px 0;
            clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 8px 50%);
          }

          &:first-child:is(:last-child) .el-breadcrumb__inner {
            background-color: var(--el-fill-color-darker);
            padding-left: 12px;
            border-radius: 6px 0 0 6px;
            clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%);
          }

          .el-breadcrumb__separator {
            display: none;
          }
        }
      }
    }
  }
}

// 面包屑动画
.breadcrumb-enter-active {
  transition: transform 0.3s, opacity 0.3s;
}

.breadcrumb-enter-from {
  opacity: 0;
  transform: translateX(30px) skewX(-50deg);
}
</style>
